<template>
    <el-container>
        <el-header>
            <div class="left-panel">
                <el-button type="primary" icon="el-icon-plus" v-auth="'order_item.create'" @click="create"></el-button>
                <el-button type="danger" plain icon="el-icon-delete" v-auth="'order_item.delete'" v-if="selection.length>0" :disabled="selection.length==0" @click="dels"></el-button>
            </div>
            <div class="right-panel">
                <div class="right-panel-search">
                    <el-input v-model="search" placeholder="搜索" @clear="this.$TABLE.searchSubmit(this)" clearable></el-input>
                    <el-button type="primary" icon="el-icon-search" @click="this.$TABLE.searchSubmit(this)"></el-button>
                    <imiFilterBar :options="options" @filterChange="filterChange"></imiFilterBar>
                </div>
            </div>
        </el-header>
        <el-main class="nopadding">
            <scTable ref="table" row-key="id" :apiObj="apiObj" :params="params" @selection-change="selectionChange" @cell-dblclick="doubleClick" stripe remoteSort remoteFilter>
                <el-table-column type="selection" width="50"></el-table-column>
                <el-table-column label="id" prop="id" >
                                    
				</el-table-column>
                <el-table-column label="用户" prop="user_id" >
                                    
				</el-table-column>
                <el-table-column label="订单" prop="order_id" >
                                    
				</el-table-column>
                <el-table-column label="商品" prop="goods_id" >
                                    
				</el-table-column>
                <el-table-column label="商品类型" prop="goods_type" >
                                    
				</el-table-column>
                <el-table-column label="规格 id" prop="goods_sku_price_id" >
                                    
				</el-table-column>
                <el-table-column label="活动 id" prop="activity_id" >
                                    
				</el-table-column>
                <el-table-column label="活动类型" prop="activity_type" >
                                    
				</el-table-column>
                <el-table-column label="活动规格|积分商城规格 id" prop="item_goods_sku_price_id" >
                                    
				</el-table-column>
                <el-table-column label="规格名" prop="goods_sku_text" >
                                    
				</el-table-column>
                <el-table-column label="商品名称" prop="goods_title" >
                                    
				</el-table-column>
                <el-table-column label="商品图片" prop="goods_image" >
                    <template #default="scope">
                    <el-avatar :src="scope.row.goods_image" size="small"></el-avatar>
                    </template>                
				</el-table-column>
                <el-table-column label="商品原价" prop="goods_original_price" >
                                    
				</el-table-column>
                <el-table-column label="优惠费用" prop="discount_fee" >
                                    
				</el-table-column>
                <el-table-column label="商品价格" prop="goods_price" >
                                    
				</el-table-column>
                <el-table-column label="购买数量" prop="goods_num" >
                                    
				</el-table-column>
                <el-table-column label="商品重量" prop="goods_weight" >
                                    
				</el-table-column>
                <el-table-column label="支付金额(不含运费)" prop="pay_price" >
                                    
				</el-table-column>
                <el-table-column label="发货状态" prop="dispatch_status" >
                    <template #default="scope">
                    <el-switch v-model="scope.row.dispatch_status" @change="this.$TABLE.change(scope.row.id,$event,'dispatch_status',this.$API.order_item.operate)" :active-value="1" :inactive-value="0"></el-switch>
                    </template>                
				</el-table-column>
                <el-table-column label="发货费用" prop="dispatch_fee" >
                                    
				</el-table-column>
                <el-table-column label="发货方式" prop="dispatch_type" >
                                    
				</el-table-column>
                <el-table-column label="发货模板" prop="dispatch_id" >
                                    
				</el-table-column>
                <el-table-column label="门店" prop="store_id" >
                                    
				</el-table-column>
                <el-table-column label="售后状态" prop="aftersale_status" >
                    <template #default="scope">
                    <el-switch v-model="scope.row.aftersale_status" @change="this.$TABLE.change(scope.row.id,$event,'aftersale_status',this.$API.order_item.operate)" :active-value="1" :inactive-value="0"></el-switch>
                    </template>                
				</el-table-column>
                <el-table-column label="评价状态" prop="comment_status" >
                    <template #default="scope">
                    <el-switch v-model="scope.row.comment_status" @change="this.$TABLE.change(scope.row.id,$event,'comment_status',this.$API.order_item.operate)" :active-value="1" :inactive-value="0"></el-switch>
                    </template>                
				</el-table-column>
                <el-table-column label="退款状态" prop="refund_status" >
                    <template #default="scope">
                    <el-switch v-model="scope.row.refund_status" @change="this.$TABLE.change(scope.row.id,$event,'refund_status',this.$API.order_item.operate)" :active-value="1" :inactive-value="0"></el-switch>
                    </template>                
				</el-table-column>
                <el-table-column label="退款金额" prop="refund_fee" >
                                    
				</el-table-column>
                <el-table-column label="退款原因" prop="refund_msg" >
                                    
				</el-table-column>
                <el-table-column label="快递公司" prop="express_name" >
                                    
				</el-table-column>
                <el-table-column label="快递公司编号" prop="express_code" >
                                    
				</el-table-column>
                <el-table-column label="快递单号" prop="express_no" >
                                    
				</el-table-column>
                <el-table-column label="附加字段" prop="ext" >
                                    
				</el-table-column>
                <el-table-column label="添加时间" prop="createtime"  align="right" width="180" :formatter="this.$TABLE.datetime">
                                    
				</el-table-column>
                <el-table-column label="更新时间" prop="updatetime"  align="right" width="180" :formatter="this.$TABLE.datetime">
                                    
				</el-table-column>
                <el-table-column label="删除时间" prop="deletetime"  align="right" width="180" :formatter="this.$TABLE.datetime">
                                    
				</el-table-column>
                <el-table-column label="平台优惠券抵用金额" prop="coupon_fee" >
                                    
				</el-table-column>
                <el-table-column label="商品总价" prop="goods_amount" >
                                    
				</el-table-column>
                <el-table-column label="支付金额" prop="total_fee" >
                                    
				</el-table-column>
                <el-table-column label="单件实际支付金额" prop="item_pay_fee" >
                                    
				</el-table-column>
                <el-table-column label="单件支付贝壳总数" prop="item_shell_fee" >
                                    
				</el-table-column>
                <el-table-column label="单件积分支付数" prop="item_score_fee" >
                                    
				</el-table-column>
                <el-table-column label="单件积分服务费金额" prop="item_score_money_fee" >
                                    
				</el-table-column>
                
                <el-table-column label="操作" fixed="right" align="right" width="140">
                    <template #default="scope">
                        <el-button type="text" v-auth="'order_item.update'" size="small" @click="update(scope.row)">编辑
                        </el-button>
                        <el-popconfirm title="确定删除吗？" @confirm="del(scope.row)">
                            <template #reference>
                                <el-button type="text" v-auth="'order_item.delete'" size="small">删除</el-button>
                            </template>
                        </el-popconfirm>
                    </template>
                </el-table-column>
            </scTable>
        </el-main>
    </el-container>
    <save-dialog v-if="dialog.save" ref="saveDialog" @success="handleSuccess" @closed="dialog.save=false"></save-dialog>
</template>
<script>
    import saveDialog from './save';
    import imiFilterBar from '@/components/imiFilterBar';
    export default {
        name: 'order_item',
        components: {
            saveDialog,
            imiFilterBar
        },
        data() {
            return {
                options: [
                    {
                        label: 'id',
                        value: 'id',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '用户',
                        value: 'user_id',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '订单',
                        value: 'order_id',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '商品',
                        value: 'goods_id',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '商品类型',
                        value: 'goods_type',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '规格 id',
                        value: 'goods_sku_price_id',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '活动 id',
                        value: 'activity_id',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '活动类型',
                        value: 'activity_type',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '活动规格|积分商城规格 id',
                        value: 'item_goods_sku_price_id',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '规格名',
                        value: 'goods_sku_text',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '商品名称',
                        value: 'goods_title',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '商品原价',
                        value: 'goods_original_price',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '优惠费用',
                        value: 'discount_fee',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '商品价格',
                        value: 'goods_price',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '购买数量',
                        value: 'goods_num',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '商品重量',
                        value: 'goods_weight',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '支付金额(不含运费)',
                        value: 'pay_price',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '发货状态',
                        value: 'dispatch_status',
                        type: 'select',
                        operator: '=',
                    	extend: {
                            data: [{label:"开启",value:1},{label:"关闭",value:0}]
	                    }
					},
					{
                        label: '发货费用',
                        value: 'dispatch_fee',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '发货方式',
                        value: 'dispatch_type',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '发货模板',
                        value: 'dispatch_id',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '门店',
                        value: 'store_id',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '售后状态',
                        value: 'aftersale_status',
                        type: 'select',
                        operator: '=',
                    	extend: {
                            data: [{label:"开启",value:1},{label:"关闭",value:0}]
	                    }
					},
					{
                        label: '评价状态',
                        value: 'comment_status',
                        type: 'select',
                        operator: '=',
                    	extend: {
                            data: [{label:"开启",value:1},{label:"关闭",value:0}]
	                    }
					},
					{
                        label: '退款状态',
                        value: 'refund_status',
                        type: 'select',
                        operator: '=',
                    	extend: {
                            data: [{label:"开启",value:1},{label:"关闭",value:0}]
	                    }
					},
					{
                        label: '退款金额',
                        value: 'refund_fee',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '退款原因',
                        value: 'refund_msg',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '快递公司',
                        value: 'express_name',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '快递公司编号',
                        value: 'express_code',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '快递单号',
                        value: 'express_no',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '附加字段',
                        value: 'ext',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '添加时间',
                        value: 'createtime',
                        type: 'datetimerange',
                        operator: 'between',
                    },
					{
                        label: '更新时间',
                        value: 'updatetime',
                        type: 'datetimerange',
                        operator: 'between',
                    },
					{
                        label: '删除时间',
                        value: 'deletetime',
                        type: 'datetimerange',
                        operator: 'between',
                    },
					{
                        label: '平台优惠券抵用金额',
                        value: 'coupon_fee',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '商品总价',
                        value: 'goods_amount',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '支付金额',
                        value: 'total_fee',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '单件实际支付金额',
                        value: 'item_pay_fee',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '单件支付贝壳总数',
                        value: 'item_shell_fee',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '单件积分支付数',
                        value: 'item_score_fee',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '单件积分服务费金额',
                        value: 'item_score_money_fee',
                        type: 'text',
                        operator: '=',
                    },
					                    
                ],
                dialog: {
                    save: false
                },
                apiObj: this.$API.order_item.read,
                selection: [],
                search: '',
                params:{},
            }
        },
        created() {
            this.$TABLE.setFilterValue(this);
        },
        mounted() {
          if(this.$route.query.id){
            this.getSubOrder(this.$route.query.id)
          }
        },
        methods: {
          // 获取自订单
          getSubOrder(id){
            console.log('执行')
            let data = {
              activity_id: "|||||=",
              activity_type: "|||||=",
              aftersale_status: "|||||=",
              comment_status: "|||||=",
              coupon_fee: "|||||=",
              createtime: "|||||between",
              deletetime: "|||||between",
              discount_fee: "|||||=",
              dispatch_fee: "|||||=",
              dispatch_id: "|||||=",
              dispatch_status: "|||||=",
              dispatch_type: "|||||=",
              express_code: "|||||=",
              express_name: "|||||=",
              express_no: "|||||=",
              ext: "|||||=",
              goods_amount: "|||||=",
              goods_id: "|||||=",
              goods_num: "|||||=",
              goods_original_price: "|||||=",
              goods_price: "|||||=",
              goods_sku_price_id: "|||||=",
              goods_sku_text: "|||||=",
              goods_title: "|||||=",
              goods_type: "|||||=",
              goods_weight: "|||||=",
              id: "|||||=",
              item_goods_sku_price_id: "|||||=",
              item_pay_fee: "|||||=",
              item_score_fee: "|||||=",
              item_score_money_fee: "|||||=",
              item_shell_fee: "|||||=",
              order_id: id+"|||||=",
              pay_price: "|||||=",
              refund_fee: "|||||=",
              refund_msg: "|||||=",
              refund_status: "|||||=",
              store_id: "|||||=",
              total_fee: "|||||=",
              updatetime: "|||||between",
              user_id: "|||||="
            }
            this.$TABLE.filter(data, this);
          },
            doubleClick(row) {
                this.update(row);
            },
            filterChange(data) {
                this.$TABLE.filter(data, this);
            },
            create() {
                this.dialog.save = true
                this.$nextTick(() => {
                    this.$refs.saveDialog.open()
                })
            },
            update(row) {
                this.dialog.save = true
                this.$nextTick(() => {
                    this.$refs.saveDialog.open('update').setData(row)
                })
            },
            async del(row) {
                var res = await this.$API.order_item.delete.post({ids: row.id});
                if (res.code == 200) {
                    this.$refs.table.refresh()
                    this.$message.success(res.message)
                } else {
                    this.$alert(res.message, "提示", {type: 'error'})
                }
            },
            async dels() {
                if (!this.selection.length) {
                    this.$message.warning("请选择要删除的数据")
                    return false;
                }
                var ids = [];
                for (const i in this.selection) {
                    ids.push(this.selection[i].id)
                }
                this.$confirm(`确定删除选中的 ${this.selection.length} 项吗？`, '提示', {
                    type: 'warning'
                }).then(() => {
                    const loading = this.$loading();
                    this.$API.order_item.delete.post({ids:ids}).then(res => {
                        if (res.code == 200) {
                            this.$refs.table.refresh()
                            this.$message.success(res.message)
                        } else {
                            this.$message.error(res.message)
                        }
                        loading.close();
                    });
                })
            },
            selectionChange(selection) {
                this.selection = selection;
            },
            handleSuccess() {
                this.$refs.table.refresh()
            }
        }
    }
</script>